//
//  HeaderView.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/11.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "HeaderView.h"
#import "UIButton+AFNetworking.h"

@interface HeaderView ()

@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UIButton *iconButton;
@property (nonatomic, strong) UILabel *nameLabel;
@end

@implementation HeaderView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self addHeadSubView];
    }
    return self;
}

- (void)addHeadSubView
{
    //添加头部背景图片
    _bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.frame.size.height)];
//    bgView.image = [UIImage imageNamed:@"person-bg"];
    _bgView.backgroundColor = [UIColor colorWithRed:208/255.0 green:206/255.0 blue:187/255.0 alpha:1];
    [self addSubview:_bgView];
    
    //添加头部那个头像
    _iconButton = [[UIButton alloc] initWithFrame:CGRectMake(_bgView.frame.size.width*0.37, _bgView.frame.origin.y + _bgView.frame.size.height*0.17 +20, _bgView.frame.size.width*0.25, _bgView.frame.size.width*0.25)];
//    [_iconButton setBackgroundImage:[UIImage imageNamed:@"_0000_头像图例"] forState:UIControlStateNormal];
//    _iconButton.backgroundColor = [UIColor redColor];
    _iconButton.layer.cornerRadius = _bgView.frame.size.width*0.25/2;
    _iconButton.clipsToBounds = YES;
    [self addSubview:_iconButton];
    [_iconButton addTarget:self action:@selector(enterSetCenter) forControlEvents:UIControlEventTouchUpInside];
    
    //添加名字
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_bgView.frame.size.width*0.33, _iconButton.frame.size.height+_iconButton.frame.origin.y, _iconButton.frame.size.width*1.4, _iconButton.frame.size.height*0.4)];
//    _nameLabel.text = @"Linda  Lv.3";
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nameLabel];
}

- (void)setUserInfo:(UserInfoModel *)userInfo {
    _userInfo = userInfo;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _bgView.frame.size.width*0.25, _bgView.frame.size.width*0.25)];
    [imageView setImageWithURL:[NSURL URLWithString:[UIUtil containString:_userInfo.headPortraits]] placeholderImage:[UIImage imageNamed:@"tupian"]];
    [_iconButton addSubview:imageView];
    self.nameLabel.text = _userInfo.nickName;
}

- (void)setImage:(UIImage *)image {
    _image = image;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _bgView.frame.size.width*0.25, _bgView.frame.size.width*0.25)];
    imageView.image = image;
    [_iconButton addSubview:imageView];
}

#pragma mark 代理
- (void)enterSetCenter
{
    if ([self.delegate respondsToSelector:@selector(enterSetCenter)]) {
        [self.delegate enterSetCenter];
    }
}
@end
